<template>
	<view class="pages">
		<view class="header">
			<view style="width: 100%;height: var(--status-bar-height)"></view>
			<view :class="isnavfixed?'active_header_top header_top':'header_top' ">
				<view class="side"><uni-icons @click="back" type="back" color="#fff" size="28"></uni-icons></view>
				<view class="header_top_center">{{$t('wallet.coupon.collectCoupons.Day')}}</view>
				<view class="side"></view>
			</view>
		</view>
		<!-- <view class="person_coupon">
			<view class="person_coupon_title">专属优惠</view>
			<view class="coupon_img" @click="getRed">
				<image src="@/static/shop/img/index/youhui.png"></image>
			</view>
		</view> -->
		<!-- 优惠券弹出 -->
		<!-- <coupon ref="coupon"></coupon> -->
		<view :class="istabfixed?'active_tab tab':'tab' ">
			<view class="t_tab">
				<u-tabs @click="change_tab" :list="typeList" lineWidth="35" lineColor="#16a5af" :activeStyle="{
				            color: '#030303',
				            fontWeight: 'bold',
				            transform: 'scale(1.15)'
				        }" :inactiveStyle="{
				            color: '#949494',
				            transform: 'scale(1.1)'
				        }" itemStyle="padding-left: 15px; padding-right: 15px; height: 44px;">
				</u-tabs>
			</view>
		</view>
		<view class="all_coupon">
			<view class="coupons_item" v-for="item in couponLists" :key="item.good_id">
				<view class="coupons_item_left">
					<image style="width: 100%;height: 100%;" :src='item.mainimg'></image>
				</view>
				<view class="coupons_item_center">
					<view class="coupons_item_center_top">{{item.good_name}}</view>
					<view class="coupons_item_center_bottom">{{$t('wallet.coupon.collectCoupons.Price')}}￥{{item.jh_price}}</view>
				</view>
				<view class="coupons_item_right">
					<view class="price">￥{{(item.money*1).toFixed(0)}}</view>
					<view class="condition">{{item.name}}</view>
					<view class="text" @click="getIt(item.id,item.good_id)">{{$t('wallet.coupon.collectCoupons.Quan')}}</view>
				</view>
			</view>
		</view>
		<view class="bottom_fixed">
			<view class="bottom_fixed_item">
				<image src="@/static/shop/img/nav/index_chose.png"></image>
				<view class="text">{{$t('wallet.coupon.collectCoupons.Receive')}}</view>
			</view>
			<view class="bottom_fixed_item" @click="go('/pages/shop/wallet/coupon/coupon')">
				<image src="@/static/shop/img/nav/mine.png"></image>
				<view class="text">{{$t('wallet.coupon.collectCoupons.Mine')}}</view>
			</view>
		</view>
	</view>
</template>

<script>
	import coupon from "@/components/shop/coupon/coupon.vue"
	import { shopCate, couponList, couponAdd } from '@/api/api.js'
	export default {
		components: {
			coupon
		},
		data() {
			return {
				isnavfixed: false,
				istabfixed: false,
				typeList: [],
				couponLists: []
			}
		},
		onShow() {
			shopCate({
				first_id: 0
			}).then(res => {
				this.typeList = res.data.data
				this.couponList(this.typeList[0].id)
			})
		},
		methods: {
			back() {
				uni.navigateBack()
			},
			go(url) {
				uni.navigateTo({
					url: url
				})
			},
			couponList(first_id){
				couponList({
					token: uni.getStorageSync('token'),
					first_id: first_id
				}).then(res=>{
					this.couponLists = res.data.data.data
				})
			},
			change_tab(e) {
				this.couponList(e.id)
			},
			getRed() {
				let child = this.$refs.coupon
				child.showNew()
			},
			getIt(coupon_id,good_id) {
				couponAdd({
					token: uni.getStorageSync('token'),
					coupon_id: coupon_id,
					good_id: good_id
				}).then(res=>{
					uni.showToast({
						title: res.data.msg,
						icon: "none"
					})
					setTimeout(() => {
						uni.navigateBack()
					}, 500)
				})
			}
		},
		onPageScroll(e) {
			this.scroll = e.scrollTop
			if (this.scroll >= 50) {
				this.isnavfixed = true
				if (this.scroll >= 330) {
					this.istabfixed = true
				} else {
					this.istabfixed = false
				}
			} else {
				this.isnavfixed = false
			}
		},
	}
</script>

<style lang="scss" scoped>
	.pages {
		min-height: 100vh;
		background-color: #f0eff4;
	}

	.header {
		width: 100%;
		height: 360rpx;
		background: url('@/static/shop/img/index/coupon_bg.png');
		background-size: 100% 100%;
		background-repeat: no-repeat;

		.header_top {
			position: fixed;
			z-index: 9;
			top: 0;
			left: 0;
			right: 0;
			padding: 0 30rpx;
			padding-top: 50rpx;
			width: 100%;
			display: flex;
			align-items: center;
			justify-content: space-between;

			.side {
				width: 15%;
			}

			.header_top_center {
				color: #fff;
				font-size: 36rpx;
			}
		}

		.active_header_top {
			background-color: #fff;

			.header_top_center {
				color: #333;
			}

			.uni-icons {
				color: #333 !important;
			}
		}
	}

	.person_coupon {
		width: 95%;
		margin: 0 auto;
		margin-top: 30rpx;
		background-color: #fff;
		border-radius: 10rpx;
		padding: 10rpx 20rpx;

		.person_coupon_title {
			margin-bottom: 15rpx;
		}

		.coupon_img {
			image {
				width: 100%;
				height: 150rpx;
			}
		}
	}

	.tab {
		font-size: 26rpx;
		padding-top: 30rpx;
		margin-bottom: 10rpx;
		width: 100%;

		.t_tab {
			width: 100%;
		}
	}

	.active_tab {
		position: fixed;
		background-color: #fff;
		z-index: 88;
		top: 120rpx;
		left: 0;
		right: 0;

	}

	.all_coupon {
		width: 95%;
		margin: 0 auto;
		padding-bottom: 120rpx;

		.coupons_item {
			width: 100%;
			height: 200rpx;
			margin-bottom: 15rpx;
			border-radius: 5rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;
			background-color: #fff;

			.coupons_item_left {
				width: 180rpx;
				height: 180rpx;
				display: flex;
				justify-content: center;
				align-items: center;
				background-color: #fff;
				margin-left: 10rpx;

				image {
					width: 100%;
					height: 100%;
				}
			}

			.coupons_item_center {
				padding: 30rpx 10rpx;
				width: 50%;
				height: 200rpx;
				display: flex;
				flex-direction: column;
				justify-content: space-between;
				background-color: #fff;
				border-radius: 0 10rpx 10rpx 0;

				.coupons_item_center_top {
					font-size: 24rpx;
					overflow: hidden;
					text-overflow: ellipsis;
					display: -webkit-box;
					-webkit-box-orient: vertical;
					-webkit-line-clamp: 2;
				}

				.coupons_item_center_bottom {
					font-size: 24rpx;
				}
			}

			.coupons_item_right {
				width: 25%;
				height: 100%;
				background-color: #3c3e54;
				border-radius: 10rpx;
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;

				.price {
					font-size: 50rpx;
					font-weight: bold;
					color: #00ffff;
				}

				.condition {
					font-size: 24rpx;
					color: #919191;
				}

				.text {
					font-size: 26rpx;
					background-color: #01c2c3;
					color: #fff;
					padding: 5rpx 15rpx;
				}
			}
		}
	}

	.bottom_fixed {
		width: 100%;
		height: 120rpx;
		background-color: #fff;
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		display: flex;
		justify-content: space-around;
		align-items: center;

		.bottom_fixed_item {
			display: flex;
			flex-direction: column;
			align-items: center;
			align-items: center;

			image {
				width: 50rpx;
				height: 50rpx;
			}

			.text {
				margin-top: 6rpx;
				font-size: 28rpx;
				color: #3f3f3f;
			}
		}
	}
</style>